﻿using System.IO;

namespace Gdmec.Util
{
    public class TxtUtil
    {
		/// <summary>
		/// 读取全部文本
		/// </summary>
		/// <param name="path"></param>
		/// <returns></returns>
		public static string ReadAllText(string path)
		{
			using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read))
			{
				using (StreamReader sr = new StreamReader(fs))
				{
					return sr.ReadToEnd();
				}
			}
		}

		/// <summary>
		/// 读取文本的某一行,从1开始读（第一行rowNum就写1）
		/// </summary>
		/// <param name="rowNum"></param>
		/// <returns></returns>
		public static string ReadTextRow(string path, int rowNum)
		{
			using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read))
			{
				using (StreamReader sr = new StreamReader(fs))
				{
					for (int i = 0; i < rowNum; i++)
					{
						string s = sr.ReadLine();
						if (i == rowNum - 1)
							return s;
					}
					return string.Empty;
				}
			}
		} 
    }
}
